<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <base href="<%=basePath%>">

    <title>add</title>

    <meta name="pragma" content="no-cache">
    <meta name="cache-control" content="no-cache">
    <meta name="expires" content="0">
    <div th:replace="~{commons/script::script}"></div>
</head>
<style type="text/css">
    .myselect{
        height:30px;
    }
</style>

<body style="width:100%;max-width:100%;padding:10px 30px;">
<form id="form" method="post">
    <strong>主要信息</strong>
    <section class="info-section">

        <table id="tb">
            <tr>
                <td class="text-title">负责人</td>
                <td class="text-content">
                    <!--<input type="hidden" name="busiVO.id" value="${busiVO.id }">
                    <input type="hidden" name="busiVO.createtime" value="${busiVO.createtime }">
                    <input type="hidden" name="busiVO.createById" value="${busiVO.createById }">-->
                    <select class="myselect" name="ownerUserId">
                        <option value="-1">请选择负责人</option>
                    </select>
                </td>
                <td class="text-title">客户</td>
                <td class="text-content">
                    <select class="myselect" name="customerId">
                        <option value="-1">请选择客户</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="text-title">商机金额</td>
                <td class="text-content">
                    <input type="text" name="totalPrice"
                           class="easyui-textbox theme-textbox-radius" data-options="required:false">
                </td>
                <td class="text-title">商机名</td>
                <td class="text-content">
                    <input type="text" name="name"
                           class="easyui-textbox theme-textbox-radius" data-options="required:false">
                </td>
            </tr>
            <tr>
                <td class="text-title">联系人</td>
                <td class="text-content">
                    <select class="myselect" name="contactsId">
                    </select>
                   <!-- <a href="javascript:void(0)" class="text-title" style="color:blue;">新建</a>-->
                </td>

            </tr>
            <tr>
                <td class="text-title" >合同签订地址</td>
                <td class="text-content" colspan="3">
                    <input type="text" style="width:550px;" name="contractAddress"
                           class="easyui-textbox theme-textbox-radius" data-options="required:false">
                </td>
            </tr>
            <tr>
                <td class="text-title">商机类型</td>
                <td class="text-content">
                    <select class="myselect" name="type">
                    </select>
                </td>
                <td class="text-title">状态</td>
                <td class="text-content">
                    <select class="myselect" name="statusId">
                    </select>
                </td>
            </tr>
            <tr>
                <td class="text-title">商机来源</td>
                <td class="text-content">
                    <select class="myselect" name="origin">
                    </select>
                </td>
                <td class="text-title">赢单率</td>
                <td class="text-content">
                    <input type="text" name="gainRate"
                           class="easyui-textbox theme-textbox-radius" data-options="required:false">
                </td>
            </tr>
            <tr>
                <td class="text-title">预定成交价</td>
                <td class="text-content">
                    <input type="text" name="estimatePrice"
                           class="easyui-textbox theme-textbox-radius" data-options="required:true">
                </td>
                <td class="text-title">下次联系时间</td>
                <td class="text-content">
                    <input class="easyui-datetimebox" name="nextstepTime" value="${busiVO.nextsteptime }"
                           data-options="required:false,showSeconds:false" style="width:150px">
                </td>
            </tr>
            <tr>
                <td class="text-title">下次联系内容</td>
                <td class="text-content">
                    <input type="text" name="nextstep"
                           class="easyui-textbox theme-textbox-radius" data-options="required:false">
                </td>

            </tr>


        </table>

    </section>
    <strong>附加信息</strong>
    <section class="info-section">
        <table>
            <tr>
                <td class="text-title">备注</td>
                <td class="text-content">
                    <textarea name="description" rows="5" style="width:80%;"></textarea>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center;margin-top: 10px;">
                    <a href="javascript:void(0);" id="saveBtn" class="easyui-linkbutton button-primary" style="margin-left:-70px;">保存</a>
                    <a href="javascript:void(0);" id="resetBtn" class="easyui-linkbutton button-danger" style="margin-left:30px;">重置</a>
                </td>
            </tr>
        </table>
    </section>
</form>

<script type="text/javascript">
    $(function(){
        //给负责人下拉框填充选项
        $.post(
            "/business/businessSystemUser",
            function(data){
                if(data&&data.data){
                    $.each(data.data,function(index,obj){
                        var option;
                        if("${sessionScope.user.id}"==obj.id){
                            option=$("<option value='"+obj.id+"' selected>"+obj.username+"</option>");
                        }else{
                            option=$("<option value='"+obj.id+"'>"+obj.username+"</option>");
                        }
                        $("select[name='ownerUserId']").append(option);

                    })
                }
            },"json"
        )
        //给客户下拉框填充选项
        $.post(
            "/business/businessCustomer",
            function(data){
                if(data&&data.data){
                    $.each(data.data,function(index,obj){
                        var option;
                        if("${customerId}"==obj.id){
                            option=$("<option value='"+obj.id+"' selected>"+obj.names+"</option>");
                        }else{
                            option=$("<option value='"+obj.id+"'>"+obj.names+"</option>");
                        }
                        $("select[name='customerId']").append(option);
                    })
                }
            },"json"
        )
        if("${customer_id}"){
            fillContacts("${customer_id}");
        }
        //给商机类型下拉框填充选项
        $.post(
            "/business/businessType",
            {
                "typecode":"businessType"
            },
            function(data){
                if(data&&data.data){
                    $.each(data.data,function(index,obj){
                        var option;
                        if(obj.type=="${type}"){
                            option=$("<option value='"+obj.id+"' selected>"+obj.type+"</option>");
                        }else{
                            option=$("<option value='"+obj.id+"'>"+obj.type+"</option>");
                        }
                        $("select[name='type']").append(option);
                    })
                }
            },"json"
        )
        //给商机状态下拉框填充选项
        $.post(
            "/business/businessStatus",
            {
                "typecode":"businessStatus"
            },
            function(data){
                if(data&&data.data){
                    $.each(data.data,function(index,obj){
                        var option;
                        if(obj.id=="${statusId}"){
                            option=$("<option value='"+obj.id+"' selected>"+obj.name+"</option>");
                        }else{
                            option=$("<option value='"+obj.id+"'>"+obj.name+"</option>");
                        }
                        $("select[name='statusId']").append(option);
                    })
                }
            },"json"
        )
        //给商机来源下拉框填充选项
        $.post(
            "/business/businessType",
            {
                "typecode":"businessOrigin"
            },
            function(data){
                if(data&&data.data){
                    $.each(data.data,function(index,obj){
                        var option;
                        if(obj.dictname=="${origin}"){
                            option=$("<option value='"+obj.id+"' selected>"+obj.origin+"</option>");
                        }else{
                            option=$("<option value='"+obj.id+"'>"+obj.origin+"</option>");
                        }
                        $("select[name='origin']").append(option);
                    })
                }
            },"json"
        )







    })
    //监听客户下拉框的事件，若更改客户则重新给联系人下拉框填充选项
    $("select[name='customerId']").on("change",function(event){
        var custId=$(this).val();
        fillContacts(custId);
    })

    //给联系人下拉框填充选项的方法
    function fillContacts(id){
        $.post(
            "/business/businessContacts",
            {
                "customer.customerid":id
            },
            function(data){
                if(data&&data.data){
                    $("select[name='contactsId']").empty();
                    if(data.data.length){
                        $.each(data.data,function(index,obj){
                            var option;
                            if(obj.id=="${contactsId}"){
                                option=$("<option value='"+obj.id+"' selected>"+obj.name+"</option>");
                            }else if(obj.isFirst){
                                option=$("<option value='"+obj.id+"' selected>"+obj.name+"(首要)</option>");
                            }else{
                                option=$("<option value='"+obj.id+"'>"+obj.name+"</option>");
                            }
                            $("select[name='contactsId']").append(option);
                        })
                    }else{
                        $("select[name='contactsId']").append("<option value='-1'>暂无数据</option>");
                    }
                }
            },"json"
        )
    }




    $(function(){
        //当页面加载完毕初始化树状下拉列表
        $("#parent").combotree({
            url : "system/function/FunctionAction_findTree.action",
            method : "get",
            loadFilter : function(data){//resultData {success:true,message:"",data:[]}
                if(data && data.success){
                    return data.data;
                }
                return null;
            }
        });

    });

    $(function() {
        //重置按钮
        $("#resetBtn").on("click",function(event){
            $("#form").form("reset");
        });
        //保存按钮
        $("#saveBtn").on("click", function(event) {
            $("#form").form("submit", {
                url : "/business/BusinessAction",
                onSubmit : function() {
                    //对表单进行数据校验,如果未通过校验，返回false，阻止表单提交
                    return $(this).form("validate");

                },
                success : function(data) {
                    //data未服务器端返回的字符串数据，eval将字符串数据转换为json对象
                    data = eval("(" + data + ")");
                    if (data.success) {
                        parent.closeTopWindow();
                    }
                }
            });
        });


    });
</script>

</body>
</html>